package android.content;

import android.VirtualAndroidUtils;
import android.content.pm.PackageManager;

/**
 * @author slc
 * @date 2022/03/29 上午 11:11
 */
public class Context {
    public static final int MODE_PRIVATE = 0;
    public static final String CONNECTIVITY_SERVICE = "connectivity";
    public static final String NOTIFICATION_SERVICE = "notification";
    public static final int RECEIVER_EXPORTED = 0x2;
    private String packageName;
    private PackageManager packageManager;

    public Context() {

    }

    public Context getApplicationContext() {
        return VirtualAndroidUtils.getApp();
    }

    public PackageManager getPackageManager() {
        return packageManager;
    }

    public void setPackageManager(PackageManager packageManager) {
        this.packageManager = packageManager;
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, int flag) {
        return registerReceiver(broadcastReceiver, intentFilter);
    }

    public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
        VirtualAndroidUtils.registerReceiver(this, broadcastReceiver, intentFilter);
        Intent intent = new Intent();
        intent.setComponent(new ComponentName(getPackageName(), broadcastReceiver.getClass().getName()));
        return intent;
    }

    public void unregisterReceiver(BroadcastReceiver broadcastReceiver) {
        VirtualAndroidUtils.unregisterReceiver(this, broadcastReceiver);
    }

    public void sendBroadcast(Intent intent) {
        VirtualAndroidUtils.sendBroadcast(this, intent);
    }

    public final ComponentName startService(Intent intent) {
        VirtualAndroidUtils.startService(this, intent);
        return intent.getComponent();
    }

    public final ComponentName startForegroundService(Intent intent) {
        startService(intent);
        return intent.getComponent();
    }

    public final boolean stopService(Intent intent) {
        VirtualAndroidUtils.stopService(this, intent);
        return true;
    }

    public final <T> T getSystemService(Class<T> tClass) {
        return VirtualAndroidUtils.getSystemService(tClass);
    }

    public final Object getSystemService(String name) {
        return VirtualAndroidUtils.getSystemService(name);
    }

    public final ContentResolver getContentResolver() {
        return VirtualAndroidUtils.getContentResolver(packageName);
    }

    public final SharedPreferences getSharedPreferences(String dataKey, int mode) {
        return VirtualAndroidUtils.getSharedPreferences(dataKey);
    }
}
